#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

typedef struct NODE {
	int v;
	int step;
}node;

int maxn;
queue<node> q;
vector<int> g[100010];
bool vis[100010];

void bfs() {
	int i;
	node p, t;

	while(!q.empty()) {
		p = q.front();
		q.pop();

		for(int i = 0; i < g[p.v].size(); i++) {
			t.v = g[p.v][i];
			t.step = p.step + 1;

			if(!vis[t.v]) {
				q.push(t);
				vis[t.v] = 1;

				if(t.step > maxn) {
					maxn = t.step;
				}
			}
		}
	}
}

int main()
{	
	node t;
	int n, p, c, m, a, b;

	scanf("%d%d%d", &n, &p, &c);
	scanf("%d", &m);
	for(int i = 0; i < p; i++) {
		scanf("%d%d", &a, &b);

		g[a].push_back(b);
		g[b].push_back(a);
	}

	t.v    = c;
	t.step = 1;
	vis[t.v] = 1;
	q.push(t);

	bfs();

	printf("%d\n", maxn+m);

	return 0;
}